/**
 * 远光ECP平台3.0版本 http://www.ygsoft.com/ Grace [Gris Application Cloud-Computing
 * Extension]
 * Copyright(c) 1998 - 2020 YGSoft.Inc, All Rights Reserved
 * 
 * ecp.component.multipleUpload.js
 * 
 * 面板展现上传控件.
 * 
 * 占位符，例如：<div id="attachmentPanel" style="width: 100%;" data-option='{}'></div>
 * 
 * 
 * 变更版本：
 * Created by zhengxianwei@ygsoft.com 2016-07-25
 */
define(["jquery", "ecp.utils", "ecp.component.upload"],function($, utils){
	/**
	 * 默认参数.
	 */
	var defaultOption = {
		showPanel: true
	};
	
	/**
	 * 声明EcpUploader对象.
	 */
	var MultipleUpload = function(control,option){
		if(!control || control.length === 0){return;}
		this.init(control,option);
		this.render();
	}
	
	/**
	 * 通过原型定义相关方法，比如渲染、赋值等等.
	 */
	MultipleUpload.prototype = {
		/**
		 * 初始化.
		 * @param {Object} control 占位符
		 * @param {Object} option 控件渲染配置属性
		 */
		init: function(control,option){
			this.control = control;
			this.option = $.extend(true, {}, defaultOption, option);
		},
		
		/**
		 * 渲染.
		 */
		render: function(){
			 this.upload = this.control.ecpUploader(this.option);
		},
		
		/**
		 * 不可用
		 */	
		disable: function(){
			 this.getUpload().control.uploadPanel("disable");
		},
		
		/**
		 * 可用
		 */	
		enable: function(){
			 this.getUpload().control.uploadPanel("enable");
		},
		
		/**
		 * 获得上传组件对象.
		 */
		getUpload: function(){
			 return this.upload;
		},
		/**
		 * 设置ywKey.
		 */
		setYwKey: function(key){
			this.upload.setYwKey(key);
		},
		/**
		 * 获取ywKey.
		 */
		getYwKey: function(){
			return this.upload.getYwKey();
		}
	};
	
	(function($) {
		var old = $.fn.multipleUpload;
		$.fn.multipleUpload = function(option){
			var me = this;
			option = option || {};
			var type = typeof(option);
			//如果第一个参数传入的是对象或空则初始化空件，如果传入的是字符串，则认为是调用里面的内部方法。
			if (type === "object") {
				var eus = [];
				this.each(function() {
					var instanceOption = $.extend({}, option, true);
					var instance = new MultipleUpload($(this), instanceOption);
					this.multipleUpload = instance;
					eus.push(instance);
				});
				if(eus.length === 1){
					eus = eus[0];
				}
				return eus;
			} else if (type === "string") {
				var args = Array.prototype.slice.call(arguments, 1);
				if (MultipleUpload.prototype[option]) {
					return MultipleUpload.prototype[option].call(args);
				}
			} else if (option === true) {
				return me[0] && me[0].multipleUpload;
			}
		};
		$.fn.multipleUpload.Constructor = MultipleUpload;
		$.fn.multipleUpload.noConflict = function() {
			$.fn.multipleUpload = old;
			return this;
		};
	}(jQuery));
	return MultipleUpload.prototype;
		
});